import com.google.common.collect.ImmutableMap;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 方法引用与lambda表达式都是对 "函数式接口" 的一个实现。
 */
public class MethodReferenceTest2 {
    // 类方法：类名.方法名
    public static void output(String s1, String s2) {
        System.out.println(s1 + "#" + s2);
    }

    public static int cal(Integer prev, Integer cur) {
        prev += cur;
        return prev;
    }

    public List<Integer> lf(List<Integer> origin) {
        return origin.stream().map(this::lf).collect(Collectors.toList());
    }

    public int lf(Integer c) {
        return c * c * c;
    }

    /**
     * static 修饰的方法不能有 this关键。
     * @param args
     */
    public static void main(String[] args) {
//        Map<String, String> map = ImmutableMap.of("a", "A", "b", "B");
//        map.forEach((k, v) -> System.out.println(k + "#" + v));
         ImmutableMap.of("a", "A", "b", "B").forEach(MethodReferenceTest2::output);

         /**
         List<Integer> list = Arrays.asList(3, 4, 5, 6, 7, 7, 9);
//         Integer sum = list.stream().reduce(0, (prev, cur) -> prev += cur);
         Integer sum = list.stream().reduce(0, MethodReferenceTest2::cal);
         System.out.println(sum);
          */

        List<Integer> list = Arrays.asList(3, 4, 5, 6, 7, 7, 9);
        MethodReferenceTest2 mrt = new MethodReferenceTest2();

//        mrt.lf(list).forEach(System.out::println);
        mrt.lf(list).forEach(s -> System.out.println(s));
    }
}
